package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.login.parameter.BindWeiXinUseroRequestDtoBean;
import com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.iapi.login.service.BindWeiXinUseroRequestDtoCall;
import com.ymatou.iapi.login.service.WeiXinUserRequestDtoCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.SingleWeiXinBriefInfoBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.SingleWeiXinBriefInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*绑定邮箱Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SingleWeiXinBriefInfo{
	private static SingleWeiXinBriefInfoBean SingleWeiXinBriefInfoBean;
	private static SingleWeiXinBriefInfoCall SingleWeiXinBriefInfoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询微信信息");
	}

	@Before
	public void caseUp() {
		SingleWeiXinBriefInfoBean=new SingleWeiXinBriefInfoBean();
		SingleWeiXinBriefInfoCall=new SingleWeiXinBriefInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(SingleWeiXinBriefInfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SingleWeiXinBriefInfo_001() {
		Logger.start(true,"联登查询微信信息,成功");
		try {
			String headimg="http://www.ymatou.com/test1.jpg";
			String logoimg="http://www.ymatou.com/test2.jpg";
			WeiXinUserRequestDtoBean bean = JUserCallService.initWeiXinUserRequestDtoBean();
			String mobile=TestDataManager.getPhoneNum();
			if(JUserCallService.mobileExists(mobile)){
				mobile=TestDataManager.getPhoneNum();
			}
			bean.setMobile(mobile);
			bean.setHeadimgurl(headimg);
			
			WeiXinUserRequestDtoCall wx = JUserCallService.weiXinUserRequestDto(bean);
			
			Integer uid=wx.getUid();
			JUserCallService.SetUserLogoCall(uid,logoimg);
			SingleWeiXinBriefInfoBean.setUserId(uid);
			SingleWeiXinBriefInfoCall.setData(SingleWeiXinBriefInfoBean);
			SingleWeiXinBriefInfoCall.callService();			
			Logger.verifyEquals("true", SingleWeiXinBriefInfoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", SingleWeiXinBriefInfoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject result = SingleWeiXinBriefInfoCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(uid, result.get("UserId").getAsInt(), "验证UserId");
			Logger.verifyEquals(bean.getName(), result.get("LoginId").getAsString(), "验证LoginId");
			Logger.verifyEquals(bean.getName(), result.get("WeiXinNickName").getAsString(), "验证WeiXinNickName");
			Logger.verifyEquals(logoimg, result.get("LogoUrl").getAsString(), "验证LogoUrl");
			Logger.verifyEquals(headimg, result.get("WeiXinLogoUrl").getAsString(), "验证WeiXinLogoUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SingleWeiXinBriefInfo_002() {
		Logger.start(true,"绑定查询微信信息,成功");
		try {
			String headimg="http://www.ymatou.com/test1.jpg";
			String logoimg="http://www.ymatou.com/test2.jpg";
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			
			
			String mobile=TestDataManager.getPhoneNum();
			if(JUserCallService.mobileExists(mobile)){
				mobile=TestDataManager.getPhoneNum();
			}
			regbean.setLoginMobile(mobile);
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid=registerResult.get("UserId").getAsInt();
			
			Thread.sleep(10000);
			
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setHeadimgurl(headimg);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			
			JUserCallService.SetUserLogoCall(uid,logoimg);
			SingleWeiXinBriefInfoBean.setUserId(uid);
			SingleWeiXinBriefInfoCall.setData(SingleWeiXinBriefInfoBean);
			SingleWeiXinBriefInfoCall.callService();			
			Logger.verifyEquals("true", SingleWeiXinBriefInfoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", SingleWeiXinBriefInfoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject result = SingleWeiXinBriefInfoCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(uid, result.get("UserId").getAsInt(), "验证UserId");
			Logger.verifyEquals(regbean.getLoginId(), result.get("LoginId").getAsString(), "验证LoginId");
			Logger.verifyEquals(bean.getWeiXinUser().getName(),result.get("WeiXinNickName").getAsString(), "验证WeiXinNickName");
			Logger.verifyEquals(logoimg, result.get("LogoUrl").getAsString(), "验证LogoUrl");
			Logger.verifyEquals(headimg, result.get("WeiXinLogoUrl").getAsString(), "验证WeiXinLogoUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SingleWeiXinBriefInfo_003() {
		Logger.start(false,"输入不存在uid,失败");
		try {
			SingleWeiXinBriefInfoBean.setUserId(999999999);
			SingleWeiXinBriefInfoCall.setData(SingleWeiXinBriefInfoBean);
			SingleWeiXinBriefInfoCall.callService();			
			Logger.verifyEquals("true", SingleWeiXinBriefInfoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100001", SingleWeiXinBriefInfoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("未查询到用户", SingleWeiXinBriefInfoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SingleWeiXinBriefInfo_004() {
		Logger.start(false,"不输入uid,失败");
		try {
//			SingleWeiXinBriefInfoBean.setUserId(999999999);
			SingleWeiXinBriefInfoCall.setData(SingleWeiXinBriefInfoBean);
			SingleWeiXinBriefInfoCall.callService();			
			Logger.verifyEquals("true", SingleWeiXinBriefInfoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100001", SingleWeiXinBriefInfoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("未查询到用户", SingleWeiXinBriefInfoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SingleWeiXinBriefInfo_005() {
		Logger.start(true,"未绑定查询微信信息,成功");
		try {
			String headimg="http://www.ymatou.com/test1.jpg";
			String logoimg="http://www.ymatou.com/test2.jpg";
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			
			
			String mobile=TestDataManager.getPhoneNum();
			if(JUserCallService.mobileExists(mobile)){
				mobile=TestDataManager.getPhoneNum();
			}
			regbean.setLoginMobile(mobile);
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid=registerResult.get("UserId").getAsInt();
			
//			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
//			bean.getWeiXinUser().setHeadimgurl(headimg);
//			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			
			JUserCallService.SetUserLogoCall(uid,logoimg);
			SingleWeiXinBriefInfoBean.setUserId(uid);
			SingleWeiXinBriefInfoCall.setData(SingleWeiXinBriefInfoBean);
			SingleWeiXinBriefInfoCall.callService();			
			Logger.verifyEquals("true", SingleWeiXinBriefInfoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", SingleWeiXinBriefInfoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject result = SingleWeiXinBriefInfoCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(uid, result.get("UserId").getAsInt(), "验证UserId");
			Logger.verifyEquals(regbean.getLoginId(), result.get("LoginId").getAsString(), "验证LoginId");
			Logger.verifyEquals("null",result.get("WeiXinNickName").toString(), "验证WeiXinNickName");
			Logger.verifyEquals(logoimg, result.get("LogoUrl").getAsString(), "验证LogoUrl");
			Logger.verifyEquals("null", result.get("WeiXinLogoUrl").toString(), "验证WeiXinLogoUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SingleWeiXinBriefInfo_006() {
		Logger.start(true,"没上传过头像未绑定查询微信信息,默认头像成功JIRACONN-15423");
		try {
//			String headimg="http://www.ymatou.com/test1.jpg";
//			String logoimg="http://www.ymatou.com/test2.jpg";
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			
			
			String mobile=TestDataManager.getPhoneNum();
			if(JUserCallService.mobileExists(mobile)){
				mobile=TestDataManager.getPhoneNum();
			}
			regbean.setLoginMobile(mobile);
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer uid=registerResult.get("UserId").getAsInt();
			
//			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
//			bean.getWeiXinUser().setHeadimgurl(headimg);
//			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			
//			JUserCallService.SetUserLogoCall(uid,logoimg);
			SingleWeiXinBriefInfoBean.setUserId(uid);
			SingleWeiXinBriefInfoCall.setData(SingleWeiXinBriefInfoBean);
			SingleWeiXinBriefInfoCall.callService();			
			Logger.verifyEquals("true", SingleWeiXinBriefInfoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", SingleWeiXinBriefInfoCall.getString("ResponseCode"), "验证ResponseCode");
			JsonObject result = SingleWeiXinBriefInfoCall.getJsonObject().get("Result").getAsJsonObject();
			Logger.verifyEquals(uid, result.get("UserId").getAsInt(), "验证UserId");
			Logger.verifyEquals(regbean.getLoginId(), result.get("LoginId").getAsString(), "验证LoginId");
			Logger.verifyEquals("null",result.get("WeiXinNickName").toString(), "验证WeiXinNickName");
			Logger.verifyEquals("http://staticontent.ymatou.com/app/userlogo/mj.jpg", result.get("LogoUrl").getAsString(), "验证LogoUrl");
			Logger.verifyEquals("null", result.get("WeiXinLogoUrl").toString(), "验证WeiXinLogoUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}